package com.zfk.transaction.service.impl;

import com.zfk.transaction.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.TIMEOUT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class RedisServiceImpl implements RedisService{

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Override
    public void set(String key, String value) {
        log.info("=== Redis存入(存活1分钟) ===");
        redisTemplate.opsForValue().set(key,value,600, TimeUnit.SECONDS);
    }

    @Override
    public String get(String key) {
        String value = null;

        if (redisTemplate.hasKey(key)){
            log.info("=== Redis查询到数据 ===");
            value = redisTemplate.opsForValue().get(key);
        }else {
            log.info("=== Redis没有查询到 ===");
        }
        return value;

    }
}
